﻿<cfscript>
/** 
* @hint "taskMarkManager - TaskMarkTurn"
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.senate.taskMarkTurnListener" 
	output=false 
	{
	
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 
	
	
	/**
	* @hint "保存网上成绩录入轮次设置"
	* 
	* @event "MachII Event Object"
	*/	
	public void function saveTurnSetting( required MachII.framework.Event event ) output=false {
		
		var turnEntity = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var instituteAllowed = "";

			var dateStart = replace(event.getArg("DateStart"), "-", "", "ALL");

			var dateEnd = replace(event.getArg("DateEnd"), "-", "", "ALL");
			
			var timeStart = replace(event.getArg("TimeStart"), ":", "", "ALL");

			var timeEnd = replace(event.getArg("TimeEnd"), ":", "", "ALL");
			
			var leaseDate = event.getArg("LeaseDate", 0);

			/* 成绩提交限制时间段 */
			if ( event.getArg("noLeaseDate") eq "1" ) {
				leaseDate = 0;
			}

			/* 选课时间段 */
			if ( event.getArg("FullDay") eq "1" ) {
				timeStart = "0001";
				timeEnd = "2359";
			}
			
			/* 允许选课学院 */
			if ( event.getArg("FullInstitute") eq "1" ) {
				instituteAllowed = "ALL";
			}
			else {
				instituteAllowed = event.getArg('targetInstitute');
			}
			
			sql = "	UPDATE
						t_mark_turn mt
					SET
						mt.date_start = :dateStart,
						mt.date_end = :dateEnd,
						mt.time_start = :timeStart,
						mt.time_end = :timeEnd,
						mt.lease_date = :leaseDate,
						mt.institute_allowed = :instituteAllowed 
					WHERE
						mt.mt = :turnId ";
						
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "turnId", value = event.getArg("MarkTurn"), cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "dateStart", value = dateStart, cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "dateEnd", value = dateEnd, cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "timeStart", value = timeStart, cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "timeEnd", value = timeEnd, cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "leaseDate", value = leaseDate, cfsqltype = "cf_sql_integer");
			queryObj.addParam(name = "instituteAllowed", value = instituteAllowed, cfsqltype = "cf_sql_varchar");
			queryObj.execute(sql = sql);
			
			
			
		}
		
	}
	
}

</cfscript>